Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(completions): improve cursor position detection #444

Merged
merged 19 commits into from
May 8, 2024

Conversation

mhanberg
Copy link
Collaborator

@mhanberg mhanberg commented Apr 30, 2024

Added a spitfire equivalent of the Code.Fragment.container_cursor_to_quoted function and that gives us the cursor position.

That will need some improvements, but is currently blocked on improving the lexer.

@mhanberg
Copy link
Collaborator Author

way too slow

{tree, id} =
ast
|> Zipper.zip()
|> Zipper.traverse(0, fn tree, id ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to keep an accumulator of the zipper when its at the spot it inserts the id, then instead of the second pass, we'll already be at the spot on the zipper to inject the cursor

@mhanberg
Copy link
Collaborator Author

error raised in Sourceror.Range.get_end_pos_for_interpolation_segments

code located in my notes as it contains work code

variables: Enum.uniq(env.variables)
}
%{
variables: Enum.uniq(env.variables)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably all the zipper stuff is slow but you could use MapSet here.

Zipper.insert_right(cursor_tree, {:__cursor__, [], []})
end

Zipper.top(cond_result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can return cond_result as well, wouldn't that be the zipper being at the cursor which you find in the with clause in the build step.

@mhanberg
Copy link
Collaborator Author

mhanberg commented May 1, 2024

Turns out most of the slowness comes from fetching the docs for every function and module.

Will omit those and fetch on the completionItem/resolve request

@mhanberg mhanberg force-pushed the improve-cursor-detection branch 2 times, most recently from 12d1d08 to fcfc15f Compare May 2, 2024 01:55
- this makes completion faster because we defer fetching docs
    - we binary_to_term/encode the relevant data to put in the data
      which then gets sent back up on the resolve request
- also includes signature in docs
- makes cursor finding faster by skipping subtrees that don't contain
  the cursor position

code is still WIP, which is why its ugly

on average of typing around in the next_ls.ex file, completions seem to
be around 45-55ms. still not as fast as I'd like them, but still
decent-ish
@mhanberg mhanberg marked this pull request as ready for review May 7, 2024 23:53
@mhanberg mhanberg merged commit ea660ee into main May 8, 2024
14 checks passed
@mhanberg mhanberg deleted the improve-cursor-detection branch May 8, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants